<template>
  <div class="icons-wrapper">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icon-box"
             v-for="item of page"
             :key="item.id"
        >
          <div class="icon-img-box">
            <img :src="item.imgUrl" class="icon-img" alt>
          </div>
          <p class="icon-description">{{item.description}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconsList: Array
  },
  data: function () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages: function () {
      let pages = []
      this.iconsList.forEach(function (item, index) {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~@/assets/css/variables.styl'
@import '~@/assets/css/mixins.styl'
.icons-wrapper{
  margin: .2rem;
}
.icons-wrapper >>> .swiper-container{
  overflow: hidden;
  width: 100%;
  height: 0;
  padding-bottom: 50%;
}

.icons-wrapper .icon-box {
  position: relative;
  float: left;
  width: 25%;
  height: 0;
  padding-bottom: 25%;
}

.icons-wrapper .icon-box .icon-img-box {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0.44rem;
}

.icons-wrapper .icon-box .icon-img-box .icon-img {
  display: block;
  margin: 0 auto;
  width: 75%;
}

.icons-wrapper .icon-box .icon-description {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  height: 0.44rem;
  line-height: 0.44rem;
  color: $darkTxtColor;
  ellipsis();
}
</style>
